/****************************************************
*	OSMF Edge Media Player version 1.2.0
* 
*	Author: Emanuele Manco
* 	E-Mail: hello@flashedge.net
*	Web: http://activeden.net/user/flashedge
*  
*****************************************************/

package net.flashedge.display 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.filters.BevelFilter;
	import flash.filters.BitmapFilterType;

	public class Volume extends MovieClip
	{
		public var hitBleed:Number = 16;
		
		public var hit:Sprite;
		public var track:Sprite;
		public var level:Sprite;
		
		public function Volume() 
		{
		}
		
		public function create( w:int, h:int, r:int, trackColor:uint, levelColor:uint, padding:Number=2) {
			
			// track
			track = new Sprite();
			track.graphics.beginFill(trackColor, 1);
			track.graphics.drawRoundRect(0, 0, w + (padding * 2), h + (padding * 2), r + padding, r + padding);
			track.graphics.endFill();
			addChild(track);
			
			// level
			level = new Sprite();
			level.mouseEnabled = false;
			level.graphics.beginFill(levelColor, 1);
			level.graphics.drawRoundRect(padding, padding, w, h, r, r);
			level.graphics.endFill();
			addChild(level);
			
			// hit area
			hit = new Sprite();
			hit.graphics.beginFill(trackColor, 0);
			hit.graphics.drawRect(0, -hitBleed*0.5, w + (padding * 2)+2, h + (padding * 2)+hitBleed);
			hit.graphics.endFill();
			addChild(hit);
		
		}
		
		public function resize(w:int, h:int, r:int, trackColor:uint, levelColor:uint, padding:Number, levelAmount:Number) {
			w = w - (padding * 2);
			var seekWidth = (track.width - (padding * 2));
			
			// track
			track.graphics.clear();
			track.graphics.lineStyle(2, 0xE2E2E2, 0.5, true);
			track.graphics.beginFill(trackColor, 1);
			track.graphics.drawRoundRect(0, 0, w + (padding * 2), h + (padding * 2), r + padding, r + padding);
			track.graphics.endFill();
			
			// level
			level.graphics.clear();
			level.graphics.beginFill(levelColor, 1);
			level.graphics.drawRoundRect(padding, padding, seekWidth*levelAmount, h, r, r);
			level.graphics.endFill();
			
			// hit area
			hit.graphics.clear();
			hit.graphics.beginFill(trackColor, 0);
			hit.graphics.drawRect(0, -hitBleed*.5, w + (padding * 2)+2, h + (padding * 2)+hitBleed);
			hit.graphics.endFill();
			
			updatelevel(levelAmount, h, r, levelColor, padding);
		}
		
		public function updatelevel( levelAmount:Number, h:Number, r:Number, levelColor:uint, padding:Number = 2) {
			
			if (levelAmount || levelAmount == 0) {
				var seekWidth = (track.width - (padding * 2)-1.5);
				
				level.graphics.clear();
				level.graphics.beginFill(levelColor, 1);
				level.graphics.drawRoundRect(padding, padding, seekWidth*levelAmount, h, r, r);
				level.graphics.endFill();
			}
		}
		
	}

}